package com.gxar.navigation.server.base.model.line.mapper;

import com.gxar.navigation.server.base.model.line.vo.request.LineCreateRequest;
import com.gxar.navigation.server.base.model.line.vo.request.LineUpdateRequest;
import com.gxar.navigation.server.base.model.line.vo.response.LineCreateResponse;
import com.gxar.navigation.server.base.model.line.vo.response.LineInfoResponse;
import com.gxar.navigation.server.base.model.line.vo.response.LinePageResponse;
import com.gxar.navigation.server.base.model.line.vo.response.LineUpdateResponse;
import com.gxar.navigation.server.db.model.LineEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author Linsy
 * @version 1.0
 * @created 2023/7/8 10:45 AM
 */
@Mapper
public interface LineMapStruct {
    LineMapStruct INSTANCE = Mappers.getMapper(LineMapStruct.class);

    /**
     * 实体转换成视图对象
     *
     * @param line 实体
     * @return 视图对象
     */
    @Mapping(target = "id", expression = "java(java.lang.String.valueOf(line.getId()))")
    @Mapping(target = "origin", ignore = true)
    @Mapping(target = "destination", ignore = true)
    @Mapping(target = "distance", expression = "java(java.math.BigDecimal.valueOf(line.getDistance()).divide(java.math.BigDecimal.valueOf(com.gxar.navigation.server.base.common.constant.MapConstant.DISTANCE_CONVERSION), 6, java.math.RoundingMode.HALF_EVEN).doubleValue())")
    LinePageResponse entityToPageResponse(LineEntity line);

    /**
     * 实体集合转视图对象集合
     *
     * @param lineEntityList 实体集合
     * @return 响应
     */
    List<LinePageResponse> entitiesToPageResponse(List<LineEntity> lineEntityList);

    /**
     * 实体转详细信息
     *
     * @param line 素材实体
     * @return 素材详细视图模型
     */
    @Mapping(target = "id", expression = "java(java.lang.String.valueOf(line.getId()))")
    @Mapping(target = "origin", ignore = true)
    @Mapping(target = "destination", ignore = true)
    @Mapping(target = "distance", expression = "java(java.math.BigDecimal.valueOf(line.getDistance()).divide(java.math.BigDecimal.valueOf(com.gxar.navigation.server.base.common.constant.MapConstant.DISTANCE_CONVERSION), 6, java.math.RoundingMode.HALF_EVEN).doubleValue())")
    LineInfoResponse entityToInfoResponse(LineEntity line);

    /**
     * 实体转创建响应
     *
     * @param line 实体
     * @return 响应
     */
    @Mapping(target = "id", expression = "java(java.lang.String.valueOf(line.getId()))")
    @Mapping(target = "origin", ignore = true)
    @Mapping(target = "destination", ignore = true)
    @Mapping(target = "distance", expression = "java(java.math.BigDecimal.valueOf(line.getDistance()).divide(java.math.BigDecimal.valueOf(com.gxar.navigation.server.base.common.constant.MapConstant.DISTANCE_CONVERSION), 6, java.math.RoundingMode.HALF_EVEN).doubleValue())")
    LineCreateResponse entityToCreateResponse(LineEntity line);

    /**
     * 实体转更新响应
     *
     * @param line 实体
     * @return 响应
     */
    @Mapping(target = "id", expression = "java(java.lang.String.valueOf(line.getId()))")
    @Mapping(target = "origin", ignore = true)
    @Mapping(target = "destination", ignore = true)
    @Mapping(target = "distance", expression = "java(java.math.BigDecimal.valueOf(line.getDistance()).divide(java.math.BigDecimal.valueOf(com.gxar.navigation.server.base.common.constant.MapConstant.DISTANCE_CONVERSION), 6, java.math.RoundingMode.HALF_EVEN).doubleValue())")
    LineUpdateResponse entityToUpdateResponse(LineEntity line);

    /**
     * 创建请求转实体
     *
     * @param createRequest 创建请求
     * @return 实体
     */
    @Mapping(target = "origin", ignore = true)
    @Mapping(target = "destination", ignore = true)
    LineEntity createRequestToEntity(LineCreateRequest createRequest);

    /**
     * 更新请求转实体
     *
     * @param updateRequest 更新请求
     * @return 实体
     */
    @Mapping(target = "origin", ignore = true)
    @Mapping(target = "destination", ignore = true)
    LineEntity updateRequestToEntity(LineUpdateRequest updateRequest);

}
